<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <meta charset="UTF-8" />
    <title>登录</title>
    <script th:src="@{js/jquery-3.1.1.js}"></script>
</head>
<body>

    <div th:if="${param.error}">
        无效的账号或密码
    </div>

    <div th:if="${param.logout}">
        你已注销
    </div>

    <form method="post" onsubmit="false">
        <div><label>账号:<input type="text" name="username" /></label></div>
        <div><label>密码:<input type="password" name="password" /></label></div>
        <div><input type="button" id="login" value="登录" /></div>
    </form>

<script>

    $("#login").click(function(){
        var name =$("input[name='username']").val();
        var ps =$("input[name='password']").val();
        var user = {"loginAccount":name,"password":ps};
        $.ajax({
            type: "POST",
            url: "http://localhost:80/api/auth/login",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify(user),
            dataType: "json",
            success:function (message) {
                alert("提交成功"+JSON.stringify(message));
            },
            error:function (message) {
                alert("提交失败"+JSON.stringify(message));
            }
        });
    });

</script>

</body>
</html>
